require('./page-extend');
App({
	globalData: {
    //用户openid
    user_openid: '',
    //用户信息
		userInfo: null,
		tabBar: [],
		homePage: '/pages/index/index',
		pages: ['/pages/index/index', '/pages/Category/Category', '/pages/introduce/introduce','/pages/my/my','/pages/shop/shop','/pages/webview/webview','/pages/address/address','/pages/addAddress/addAddress','/pages/checkToBuy/checkToBuy','/pages/forum/forum','/pages/publish/publish','/pages/forumIntroduce/forumIntroduce']
	},
	onLaunch() {
    wx.cloud.init({
      env:'cloud1-3g89eqc54169554f'
    }),
    wx.cloud.callFunction({
      name:'login',
      success:res=>{
        this.globalData.user_openid=res.result.openid
          //在数据库中查找用户是否已经登录过了
          wx.cloud.database().collection('userInfo').where({
            _openid: res.result.openid
          }).get({
            success: result => {
              this.globalData.userInfo = result.data[0]
            }
          })
      }
    })

		wx.getSystemInfo({
			success: (e) => {
				this.globalData.StatusBar = e.statusBarHeight;
				let capsule = wx.getMenuButtonBoundingClientRect();
				this.globalData.WindowWidth = e.windowWidth;
				this.globalData.PixelRatio = 750 / e.windowWidth;
				if (capsule) {
					this.globalData.Custom = capsule;
					this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
				} else {
					this.globalData.CustomBar = e.statusBarHeight + 50;
				}
			}
		});
  },
  onLoad: function (options) {
    this.setData({
      userInfo: app.globalData.userInfo
    })
  },

	onShow() {},
	onHide() {}
});
